/*
 * This is super messy guys, try cleaning it up.
 * -Cal
 * That's not going to happen.
 * -Darius
*/

import java.util.*;
import java.io.*;
import javax.swing.*;
public class library{
	//stats
	public static void stats(){ // display player stats

		JOptionPane.showMessageDialog(null, "Your strength is: "+textrpg.lstr+"\n Your speed is: "+textrpg.lspeed+
				"\nYour health is: "+textrpg.health+"\n Your overall level is: "+textrpg.lave+" \nTo look at your stats just type ''stats'' into the action bar.");
	}
	//inventory
	public static void inventory(){  // display inventory
		String f="";
		for (int i=1;i<textrpg.Inventory.size();i++){
			if (!textrpg.Inventory.get(i).equals("0"))
				f=f.concat(textrpg.Inventory.get(i)+'\n');
		}
		JOptionPane.showMessageDialog(null, "Inventory:\n"+f);
	}
	//training
	public static void training(){  // a way to increase levels

		int choice=Integer.parseInt(JOptionPane.showInputDialog("1 - lift weights \n 2 - go to the race track \n 3 - eat pastries \n 4 - all of the above \n 5 - back to town"));
		if (choice<4){level_up(choice);}
		else if (choice==4){level_up();}
		else {return;}
	}
	//help
	public static void help(){  //display commands
		String total="save\nquit\nhelp\nstats\ninventory\ntraining\n\nLocation Commands:\n\n";
		int i=0;
		while (textrpg.Help[i] != null){
			total=total.concat(textrpg.Help[i]+'\n');
			i++;
		}
		JOptionPane.showMessageDialog(null,"Available Commands:\n\n"+total);  // show all subset names

	}
	// training specifics
	private static void level_up(int type){ // specifically levels up skills
		textrpg.money-=2;
		if (type==1){textrpg.lstr++; textrpg.dmg+=5;}
		else if (type==2){textrpg.lspeed++;}
		else if (type==3){textrpg.lhealth++;}
	}
	//level up
	private static void level_up(){ // generic leveling
		textrpg.money-= 5;
		textrpg.lstr++;
		textrpg.lspeed++;
		textrpg.lhealth++;
		textrpg.dmg+=5;
	}

	//a
	public static void a(){
		Arrays.fill(textrpg.Help, null);
		textrpg.Help[0]="sleep";
		textrpg.Help[1]="look in the chest";
		textrpg.Help[2]="go out the door";
		String a;
		a = JOptionPane.showInputDialog( "There is a bed to my left  and a chest to my right.  I hear the sounds of children through the door.").toLowerCase();
		if (a.equals("sleep")){JOptionPane.showMessageDialog(null,"I go to sleep. I have a strange dream about a demon and the end of the world"); a();}
		else if (a.equals("look in the chest")){
			if (textrpg.done[0]==false){if (textrpg.Inventory.size()<=textrpg.packspace) {JOptionPane.showMessageDialog(null,"I got a thing!!!!!\n A sword was added to my inventory."); textrpg.Inventory.add("wooden sword");
			textrpg.done[0]=true; equip(5);
			a();}
			else {hoarder();a();}
			}
			else {JOptionPane.showMessageDialog(null, "It was empty...");a();}
		}
		else if (a.equals("go out the door")){b();}
		else {normalmenu(a);a();}
	}

	//b
	public static void b(){
		Arrays.fill(textrpg.Help, null);
		textrpg.Help[0]="Play with the children";
		textrpg.Help[1]="Kill the children";
		textrpg.Help[2]="Walk to the store";
		textrpg.Help[3]="Go inside house";
		textrpg.Help[4]="Go to outer AldrÃ¤nia";
		String b;
		b = JOptionPane.showInputDialog("There are children playing to the left, a store straight ahead, and a road to outer AldrÃ¤nia.").toLowerCase();
		if (b.equals("play with the children")){JOptionPane.showMessageDialog(null, "I go over and play with the neighborhood children.");b();}
		else if (b.equals("kill the children")){JOptionPane.showMessageDialog(null, "I attack the children but they call me such cruel names that I run away.");b();}
		else if (b.equals("walk to the store")){outsidethestore();}
		else if (b.equals("go inside house")){a();}
		else if (b.equals("go to outer aldrania")){outeraldrania();}
		else {normalmenu(b);b();}

	}

	// outsidethestore
	public static void outsidethestore(){
		Arrays.fill(textrpg.Help, null);
		textrpg.Help[0]="walk into the store";
		textrpg.Help[1]="go home";
		textrpg.Help[2]="vandalize storefront";
		String outsidethestore;
		outsidethestore = JOptionPane.showInputDialog("I walk to the store. Should I walk in?").toLowerCase();
		if (outsidethestore.equals("walk into the store")){insidethestore();}
		else if (outsidethestore.equals("go home")){b();}
		else if (outsidethestore.equals("vandalize storefront")){JOptionPane.showMessageDialog(null, "You try to scratch the front of the\nstore with your fingernails, but ultimately fail.");}
		else {normalmenu(outsidethestore);outsidethestore();}
	}

	// insidethestore
	public static void insidethestore(){
		String insidethestore;
		insidethestore = JOptionPane.showInputDialog("The lady at the counter is selling a potion for three Moneys \n a backpack for eight Moneys\n a book for  five Moneys\n and a map for two Moneys").toLowerCase();
		// potion
		if (insidethestore.equals("buy a potion")) {if (textrpg.money>=3) {if (textrpg.Inventory.size()<=textrpg.packspace){JOptionPane.showMessageDialog(null, "You bought a potion for three Moneys.\n A potion restores your health by ten points up to your max."); textrpg.money -= 3;
		textrpg.Inventory.add("potion");}
		else {hoarder();}
		}
		else {poorandhomeless(3-textrpg.money);}
		}
		// map
		else if (insidethestore.equals("buy a map")){if (textrpg.done[2]=false){
			if (textrpg.money>= 2) {JOptionPane.showMessageDialog(null, "You bought a map for two Moneys. \n The map lets you travel to wherever you want");
			textrpg.money -= 2;
			textrpg.done[2]=true;}
			else {poorandhomeless(2-textrpg.money);}
		}
		else {owned();}
		}
		// backpack
		else if (insidethestore.equals("buy a backpack")) {if (textrpg.done[1]=true){
			if (textrpg.money>=8) {JOptionPane.showMessageDialog(null, "You bought a backpack for eight Moneys.\n A backpack increases your inventory to 10 slots.");
			textrpg.money -= 8;
			textrpg.done[1]=true;
			textrpg.packspace=11;}
			else {poorandhomeless(8-textrpg.money);}
		}
		else {owned();}
		}
		// leave
		else if(insidethestore.equals("leave the store")){outsidethestore();}

		else {normalmenu(insidethestore);insidethestore();}
	}

	//outer aldrania
	public static void outeraldrania(){
		Arrays.fill(textrpg.Help, null);
		textrpg.Help[0]="Go back to Aldrania";
		textrpg.Help[1]="Go into the cave";
		textrpg.Help[2]="Follow the road";
		String outeraldrania=JOptionPane.showInputDialog(null, "I walk to the outside of town. It feels kind of cold\n There is a cave and a road but I think a dragon lives in the cave.\n I am kind of scared...").toLowerCase();
		if (outeraldrania.equals("go back to aldrania")){b();}
		if (outeraldrania.equals("follow the road")){castlegrownstone();}
		if (outeraldrania.equals("go into the cave")){cave1();}
		else {normalmenu(outeraldrania);outeraldrania();}
	}


	public static void cave1(){
		Arrays.fill(textrpg.Help, null);
		if (textrpg.Inventory.contains("torch")==true){
			Arrays.fill(textrpg.Help, null);
			textrpg.Help[0]="Explore the cave";
			textrpg.Help[1]="Leave the cave";
			textrpg.Help[2]="Play in the puddle";
			String cave1=JOptionPane.showInputDialog(null, "There is a huge hole in the wall that I could go through to see more... or I could just leave.\n There is also a large puddle in the corner that looks like fun.").toLowerCase();   
			if (cave1.equals("play in the puddle")){textrpg.Inventory.add("dark ring of antidragon");
			JOptionPane.showMessageDialog(null, "I picked up a \"Dark Ring of Antidragon\".\n Maybe this will come in handy at a later time...");
			cave1();}
			else if (cave1.equals("leave the cave")){JOptionPane.showMessageDialog(null,"Even with the torch the cave looks too scary. \n I think that exploring will have to wait for a future time.");
			outeraldrania();}
			//   else if (cave1.equals("explore the cave")){intothecave();}
			else{normalmenu(cave1);cave1();}

		}
		else {JOptionPane.showMessageDialog(null,"The cave makes my skin feel like it is burning.\n As I stumble out of the cave I feel my energy draining");
		textrpg.health -=3;
		outeraldrania();} 

	}


	public static void castlegrownstone(){
		Arrays.fill(textrpg.Help, null);


	}



	//menounderstand
	public static void menounderstand(String a){
		JOptionPane.showMessageDialog(null, "I don't know what ''"+a+"'' means...");
	}




	//poorandhomeless
	public static void poorandhomeless(int a){
		if (a>1) {JOptionPane.showMessageDialog(null, "You don't have enough Moneys.\nYou need "+a+" more Moneys.");}
		else {JOptionPane.showMessageDialog(null, "You don't have enough Moneys.\nYou need "+a+" more money.");}
	}

	//hoarder
	public static void hoarder(){
		JOptionPane.showMessageDialog(null, "You don't have room for that in your inventory.");}
	public static void owned(){
		JOptionPane.showMessageDialog(null, "You already have one");
	}

	//normalmenu
	public static void normalmenu(String act){
		if (act.toLowerCase().equals("stats"))
			stats();
		else if (act.toLowerCase().equals("inventory"))
			inventory();
		else if (act.toLowerCase().equals("training"))
			training();
		else if (act.toLowerCase().equals("help"))
			help();
		//else if (act.toLowerCase().equals(""))
		//method.();
		else if (act.toLowerCase().equals("quit")){
			System.exit(0);
		}
		else if (act.toLowerCase().equals("save")){
			try {
				textrpg.Saving();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		else
			menounderstand(act);
	}

	//equip
	public static void equip(int dmg){
		String[] ops=new String[2];
		ops[0]="Yes";
		ops[1]="No";
		int yn=JOptionPane.showOptionDialog(null,"Your current weapon does "+textrpg.wpn+".\nThis sword does "+dmg+".\nDo you wish to equip?", "", JOptionPane.PLAIN_MESSAGE, -1, null, ops,ops[0]);
		if (yn==0)
			textrpg.wpn=dmg;
		else
			JOptionPane.showMessageDialog(null, "You can always equip this weapon from your inventory.");
		textrpg.dmg=textrpg.wpn+textrpg.lstr*5;
	}
	public static boolean search(Object[] array, Object term){
		for (int index=0; index<array.length; index++){
			if (array[index]==term)
				return true;
		}
		return false;
	}
}

